#include <stdio.h>
#include <signal.h>
#include <string.h>

#include "init.h"
#include "externs.h"

void SIG_HANDLE(int sig) {
    printf("\n[minishell]$ ");
    fflush(stdout);
}

void setup() {
    signal(SIGINT, SIG_HANDLE);
    signal(SIGQUIT, SIG_IGN);  // 忽略信号:  Ctrl + 反斜杠
}

void init() {
    memset(cmd,     0, sizeof(cmd));    // 解析出来的命令
    for(int i = 0; i < PIPELINE; ++i) {
        cmd[i].infd  = 0;
        cmd[i].outfd = 1;
    }

    memset(cmdline, 0, sizeof(cmdline));   // 读到的命令
    memset(avgline, 0, sizeof(avgline));

    lineptr = cmdline;
    avptr   = avgline;

    memset(infile,  0, sizeof(infile));
    memset(outfile, 0, sizeof(outfile));

    cmd_count = 0;
    backgnd   = 0;
    append    = 0;
    lastpid   = 0;

    printf("[minishell]$ ");
    fflush(stdout);
}
